package SSM.Chat.Utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

public class Request {

    /**
     * 解析网页发送的网络请求头部信息
     * @param request  传递网络请求
     * @return  返回token字符串，字符串没有值返回null
     */
    public String Axios(HttpServletRequest request) {
        Map<String, String> map = new HashMap<String, String>();
        Enumeration headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String key = (String) headerNames.nextElement();
            String value = request.getHeader(key);
            map.put(key, value);
        }
        String token = map.get("token");
        return token;
    }

    public Collection<String> AxiosResponse(HttpServletResponse response) {
        Map<String, String> map = new HashMap<String, String>();
        Collection<String> headerNames = response.getHeaderNames();

        return headerNames;
    }
}
